package jeesample.jaxrs;

import java.util.List;

import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import jeesample.dtos.RoomDTO;
import jeesample.service.publishers.LocatorServicePublisher;

import org.apache.log4j.Logger;
import org.glassfish.jersey.server.JSONP;

@Path("locator")
public class LocatorRS extends BaseRESTfulService {
	private Logger logger = Logger.getLogger(getClass());

	@Override
	protected Logger logger() {
		// TODO Auto-generated method stub
		return logger;
	}

	private LocatorServicePublisher publisher = new LocatorServicePublisher();

	@GET
	@Path("/rooms")
	@JSONP
	@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
	public List<RoomDTO> listAllRooms() {
		dbg("listAllRooms()");
		return publisher.listAllRooms();
	}

	@GET
	@Path("/rooms/{location}")
	@JSONP
	@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
	public List<RoomDTO> listRoomsIn(@PathParam("location") String location) {
		dbg("listRoomsIn(" + location + ")");
		return publisher.listRoomsIn(location);
	}

	@GET
	@Path("/locations")
	@JSONP
	@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
	public List<String> listAllLocations() {
		dbg("listAllLocations()");
		return publisher.listAllLocations();
	}

	@POST
	@Path("/rooms")
	@JSONP
	@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
	public RoomDTO addRoom(RoomDTO dto) {
		dbg("addRoom(" + dto + ")");
		return publisher.addRoom(dto);
	}

	@DELETE
	@Path("/rooms/{roomId}")
	@JSONP
	@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
	public String deleteRoom(@PathParam("roomId") String roomId) {
		dbg("deleteRoom(" + roomId + ")");
		RoomDTO dto = new RoomDTO();
		dto.setRoomId(roomId);
		return publisher.deleteRoom(dto);
	}
}
